package com.bdqn.datajap.repository;

import com.bdqn.datajap.pojo.SysUser;
import com.bdqn.datajap.vo.UserInfo;
import org.apache.catalina.User;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.FluentQuery;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public interface UserRepository extends JpaRepository<SysUser, Integer>, JpaSpecificationExecutor<SysUser> {

//模糊查询

    List<SysUser> findByUsrNameLike(String name);

//    @Query("select u from SysUser u where u.usrRoleId = ?1")
//    List<SysUser> findByRoleId(Integer roleId);
//@Transactional(timeout = 10)
//    @Modifying
//    @Query("select u from SysUser u where u.usrRoleId = :roleId")
//    List<SysUser> findByRoleId(@Param("roleId") Integer roleId);

//     List<SysUser> findUserByName(String usrName);

     //分页查询
    @Query("select u from SysUser u where u.sysRole.roleId = ?1")
     Page<SysUser> findPageByUsrRoleId(Integer roleId,Pageable pageable);
     @Query("select u.usrName as usrName,u.usrId as usrId,r.roleName as roleName from SysUser u,SysRole r where u.sysRole.roleId=r.roleId and u.usrId=?1")
     UserInfo getUerInfo(Integer usrId);
}
